package com.triones.api.mapper.interlace;

import com.ruoyi.common.core.mapper.BaseMapperPlus;
import com.triones.api.entity.interlace.dto.InterlaceCardBillStatisticsDO;
import com.triones.api.entity.interlace.vo.InterlaceCardBillStatisticsVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

/**
 * 银行卡账单统计
 */
public interface InterlaceCardBillStatisticsMapper extends BaseMapperPlus<InterlaceCardBillStatisticsMapper, InterlaceCardBillStatisticsDO, InterlaceCardBillStatisticsVO> {

    /**
     * 原子性减少统计金额（消费之类的支出类型）
     * @param id 主键ID
     * @param quoteAmount 要减少的金额
     * @return 更新记录数
     */
    @Update("UPDATE tr_interlace_card_bill_statistics SET amount = amount - #{quoteAmount}, last_date = #{updateTime} " +
        "WHERE id = #{id}")
    int decreaseAmount(@Param("id") Long id,
                       @Param("quoteAmount") BigDecimal quoteAmount,
                       @Param("updateTime") Long updateTime);

    /**
     * 原子性增加统计金额（退款等收入类型）
     * @param id 主键ID
     * @param quoteAmount 要增加的金额
     * @return 更新记录数
     */
    @Update("UPDATE tr_interlace_card_bill_statistics SET amount = amount + #{quoteAmount}, last_date = #{updateTime} " +
        "WHERE id = #{id}")
    int increaseAmount(@Param("id") Long id,
                       @Param("quoteAmount") BigDecimal quoteAmount,
                       @Param("updateTime") Long updateTime);
}
